package com.sunwayworld.basemodule.basedata.instrumentresult.service.impl;

import com.sunwayworld.basemodule.basedata.instrumentresult.bean.InstrumentResultBean;
import com.sunwayworld.basemodule.basedata.instrumentresult.dao.InstrumentResultDao;
import com.sunwayworld.basemodule.basedata.instrumentresult.service.InstrumentResultService;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@GikamBean
public class InstrumentResultServiceImpl implements InstrumentResultService {

    @Autowired
    private InstrumentResultDao instrumentResultDao;

    @Override
    @SuppressWarnings("unchecked")
    public InstrumentResultDao getDao() {
        return instrumentResultDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        InstrumentResultBean instrumentResult = jsonWrapper.parseUnique(InstrumentResultBean.class);
        instrumentResult.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(instrumentResult);
        return instrumentResult.getId();
    }

}
